import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GTextFormat } from "../../../common/GTextFormat";
import { BaseItem } from "../common/BaseItem";
import { NumberTool } from "./NumberTool";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { ItemData } from "../../resource/info/ItemData";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { ItemConfig } from "../../resource/ItemConfig";
import { SceneConfig } from "../../resource/SceneConfig";
import { MapFileUtil } from "../../scene/map/MapFileUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { SPlayerItem } from "../../../../Message/Public/SPlayerItem";
type int = number;
//class SelfGoodsRenderer
    
    export  class SelfGoodsRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            this._greenTf = new GTextFormat("", 12, 6350622);
            this._redTf = new GTextFormat("", 12, 16711680);
            this._whiteTf = new GTextFormat("", 12, 16777215);
            this._blueTf = new GTextFormat("", 12, 11661311);
            this._item = new BaseItem();
            this._item.setSize(30, 30);
            this._item.move(0, 1);
            this._item.setAmountLabelPos(0, 16);
            addChild(this._item);
            this._goodsName = this.createTextfield(35, 5, 60, 20, "", this._blueTf);
            this._unitPriceSell = this.createTextfield(105, 5, 60, 20, "", this._blueTf);
            this._unitPriceBuy = this.createTextfield(165, 5, 60, 20, "", this._blueTf);
            this._unitProfitOrLoss = this.createTextfield(225, 5, 60, 20, "", this._whiteTf);
            this._allProfitOrLoss = this.createTextfield(280, 5, 60, 20, "", this._whiteTf);
            this._numberTool = new NumberTool();
            this._numberTool.x = 335;
            this._numberTool.y = 5;
            this._numberTool.addEventListener(EventName.NumberToolAmountChange, this.onNumberToolAmountChangeHandler);
            addChild(this._numberTool);
            this._sellBtn = new GButton();
            this._sellBtn.setSize(38, 22);
            this._sellBtn.move(363, 5);
            this._sellBtn.label = Language.getString(35316);
            this._sellBtn.styleName = "Button";
            this._sellBtn.drawNow();
            this._sellBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSellBtnClickHandler);
            addChild(this._sellBtn);
            var loc1=ObjCreate.createBg(0, 32, 400, 2, this, ImagesConst.SplitLine);
            this._camp = Cache.instance.role.playerInfo.camp;
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1=null;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.selectable = false;
            loc1.mouseEnabled = false;
            loc1.setTextFormat(arg6);
            addChild(loc1);
            return loc1;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc10=0;
            super.data = arg1;
            this._sPlayerItem = (arg1 as ItemData).data;
            this._itemCode = this._sPlayerItem.itemCode;
            var loc1=new ItemData(this._itemCode);
            this._item.itemData = loc1;
            this._item.drawNow();
            this._item.amount = this._sPlayerItem.itemAmount;
            var loc2=JSON.deserialize(this._sPlayerItem.jsStr);
            var loc3=loc2.rb_buy;
            var loc4=loc2.rb_buy_map;
            this._numberTool.maxNumber = this._sPlayerItem.itemAmount;
            this._numberTool.currentNumber = this._sPlayerItem.itemAmount;
            var loc5=ItemConfig.instance.getInfoByCode(loc1.itemCode).item.name;
            this._goodsName.text = loc5;
            this._goodsName.setTextFormat(this._blueTf);
            var loc6=Cache.instance.dialog.npcInfo.tnpc.npcId;
            var loc7=Cache.instance.runBusiness.getItemSellByNpcAndItemCode(this._itemCode);
            var loc8;
            var loc9=(loc8 = SceneConfig.instance.getSceneInfo(MapFileUtil.mapID)).sMapDefine.campType.__value;
            if (MapFileUtil.mapID != loc4) 
            {
                if (MapFileUtil.mapID == 400101 || loc4 == 400101) 
                {
                    loc10 = loc7.neutralCampSellPrice;
                }
                else 
                {
                    loc10 = loc7.otherCampSellPrice;
                }
            }
            else 
            {
                loc10 = loc7.selfCampSellPrice;
            }
            this._unitPriceSell.text = loc10.toString();
            this._unitPriceSell.setTextFormat(this._blueTf);
            this._unitPriceBuy.text = loc3.toString();
            this._unitPriceBuy.setTextFormat(this._blueTf);
            this._unitProfitOrLossNum = loc10 - loc3;
            var loc11=this._unitProfitOrLossNum * this._numberTool.number;
            if (this._unitProfitOrLossNum > 0) 
            {
                this._unitProfitOrLoss.text = "+" + this._unitProfitOrLossNum;
                this._unitProfitOrLoss.setTextFormat(this._greenTf);
                this._allProfitOrLoss.text = "+" + loc11;
                this._allProfitOrLoss.setTextFormat(this._greenTf);
            }
            else if (this._unitProfitOrLossNum < 0) 
            {
                this._unitProfitOrLoss.text = "-" + Math.abs(this._unitProfitOrLossNum);
                this._unitProfitOrLoss.setTextFormat(this._redTf);
                this._allProfitOrLoss.text = "-" + Math.abs(loc11);
                this._allProfitOrLoss.setTextFormat(this._redTf);
            }
            else if (this._unitProfitOrLossNum == 0) 
            {
                this._unitProfitOrLoss.text = "0";
                this._unitProfitOrLoss.setTextFormat(this._whiteTf);
                this._allProfitOrLoss.text = "0";
                this._allProfitOrLoss.setTextFormat(this._whiteTf);
            }
            return;
        }

        /* internal  */onNumberToolAmountChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._unitProfitOrLossNum * this._numberTool.number;
            if (this._unitProfitOrLossNum > 0) 
            {
                this._allProfitOrLoss.text = "+" + loc1;
                this._allProfitOrLoss.setTextFormat(this._greenTf);
            }
            else if (this._unitProfitOrLossNum < 0) 
            {
                this._allProfitOrLoss.text = "-" + Math.abs(loc1);
                this._allProfitOrLoss.setTextFormat(this._redTf);
            }
            else if (this._unitProfitOrLossNum == 0) 
            {
                this._allProfitOrLoss.text = "0";
                this._allProfitOrLoss.setTextFormat(this._whiteTf);
            }
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onSellBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RunBusinessSellGoods, {"uid": this._sPlayerItem.uid, "amount": this._numberTool.number}));
            return;
        }

        /* internal */ /* var */_greenTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_redTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_whiteTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_blueTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_goodsName: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitPriceSell: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitPriceBuy: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitProfitOrLoss: Object /* flash.text.TextField */;

        /* internal */ /* var */_allProfitOrLoss: Object /* flash.text.TextField */;

        /* internal */ /* var */_numberTool: NumberTool;

        /* internal */ /* var */_sellBtn: GButton;

        /* internal */ /* var */_camp: int;

        /* internal */ /* var */_itemCode: int;

        /* internal */ /* var */_unitProfitOrLossNum: int;

        /* internal */ /* var */_sPlayerItem: SPlayerItem;
    }
